<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2024/8/23
  Time: 20:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>updateOrders</title>
    <link href="../../../static/layui/css/layui.css" rel="stylesheet">
</head>
<body>
    <script src="../../../static/layui/layui.js" type="text/javascript" charset="UTF-8"></script>
    <script src="../../../static/jquery-2.1.4.js" type="text/javascript" charset="UTF-8"></script>
    <script src="../../../static/mylayer.js" type="text/javascript" charset="UTF-8"></script>
    <script src="../../../static/kindeditor/kindeditor.js" type="text/javascript" charset="utf-8"></script>

    <form class="layui-form layui-form-pane" lay-filter="formFilter" action="">
        <input type="hidden" name="id">

        <div class="layui-form-item">
            <label class="layui-form-label">医生姓名</label>
            <div class="layui-input-block">
                <select id="userId" name="userId">
                    <option value="">请选择开具医生</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">病人姓名</label>
            <div class="layui-input-block">
                <select id="patientId" name="patientId">
                    <option value="">请选择所属病人</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">药品数量</label>
            <div class="layui-input-block">
                <select id="number" name="number">
                    <option value="">请选择药品数量</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="submitDemo">修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script>
        layui.use(['form'], function () {
            var form = layui.form;

            var queryString = window.location.search;
            var urlParams = new URLSearchParams(queryString);
            var id = urlParams.get("id");
            console.log("id: " + id);

            $.post(
                "/order?method=selectMap",
                {"id": id},
                function (result) {
                    console.log(result);
                    if (result.code == 0) {
                        $(result.data.userList).each(function () {
                            $('#userId').append('<option value="' + this.id + '">' + this.name + '</option>');
                        });
                        form.render("select");
                        $(result.data.patientList).each(function () {
                            $('#patientId').append('<option value="' + this.id + '">' + this.name + '</option>');
                        });
                        form.render("select");
                        $(result.data.inventoryList).each(function () {
                            $('#number').append('<option value="' + this.quantity + '">' + this.quantity + '</option>');
                        });
                        form.render("select");

                        form.val("formFilter", result.data.order);
                    }
                },
                'json'
            );

            //监听提交
            form.on('submit(submitDemo)', function (data) {
                // layer.alert(JSON.stringify(data.field), {
                //     title: '最终的提交信息'
                // })
                console.log(data.field);
                $.post(
                    '/order?method=update',
                    data.field,
                    function (result) {
                        console.log(result);
                        if (result.code == 0) {
                            mylayer.okMsg(result.msg);
                            setInterval(function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                window.parent.location.reload();
                            }, 2000);
                        }
                    },
                    'json'
                )
                return false;
            });
        })
    </script>
    <a></a>
</body>
</html>
